{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "56ab457f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入相关的库\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "from sklearn.metrics import confusion_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "2438c0eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读取数据集\n",
    "dataset = pd.read_csv('data/user_data.csv', encoding='gbk')\n",
    "X = dataset.iloc[:, 2:4].values\n",
    "y = dataset.iloc[:, 4].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "314e78f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>用户ID</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>预计工资</th>\n",
       "      <th>是否购买</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>15624510</td>\n",
       "      <td>Male</td>\n",
       "      <td>19</td>\n",
       "      <td>19000</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>15810944</td>\n",
       "      <td>Male</td>\n",
       "      <td>35</td>\n",
       "      <td>20000</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>15668575</td>\n",
       "      <td>Female</td>\n",
       "      <td>26</td>\n",
       "      <td>43000</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>15603246</td>\n",
       "      <td>Female</td>\n",
       "      <td>27</td>\n",
       "      <td>57000</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>15804002</td>\n",
       "      <td>Male</td>\n",
       "      <td>19</td>\n",
       "      <td>76000</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       用户ID      性别  年龄   预计工资  是否购买\n",
       "0  15624510    Male  19  19000     0\n",
       "1  15810944    Male  35  20000     0\n",
       "2  15668575  Female  26  43000     0\n",
       "3  15603246  Female  27  57000     0\n",
       "4  15804002    Male  19  76000     0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "266b2431",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[   19, 19000],\n",
       "       [   35, 20000],\n",
       "       [   26, 43000],\n",
       "       [   27, 57000],\n",
       "       [   19, 76000]], dtype=int64)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "1da684a8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0, 0, 0], dtype=int64)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "14eebe92",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(400, 2) (300, 2) (100, 2)\n"
     ]
    }
   ],
   "source": [
    "# 将数据集切分为训练集和测试集\n",
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test =train_test_split(X,y,test_size= 0.25, random_state=88)\n",
    "\n",
    "print(X.shape,X_train.shape,X_test.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "952c4e44",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.99513555 -0.82080737]\n",
      " [ 0.99513555 -1.14326741]\n",
      " [ 1.474796    0.08794365]\n",
      " [-0.25198162  0.17588729]\n",
      " [ 0.13174674  0.1172582 ]\n",
      " [ 0.22767883  2.13996207]\n",
      " [-0.63570998 -1.58298564]\n",
      " [-0.25198162 -0.1172582 ]\n",
      " [-0.63570998  0.14657274]\n",
      " [ 1.09106764 -1.2018965 ]\n",
      " [-0.25198162  0.29314549]\n",
      " [ 0.99513555  1.90544568]\n",
      " [ 0.22767883 -0.29314549]\n",
      " [ 0.89920346 -0.52766188]\n",
      " [ 0.80327137 -1.2018965 ]\n",
      " [-1.11537043 -1.55367109]\n",
      " [ 0.03581465  1.28984015]\n",
      " [ 0.41954301 -0.14657274]\n",
      " [ 0.13174674  1.90544568]\n",
      " [-0.82757416 -0.76217827]\n",
      " [ 0.32361092  0.08794365]\n",
      " [-1.59503088 -0.02931455]\n",
      " [-1.49909879 -0.17588729]\n",
      " [-1.21130252  0.32246004]\n",
      " [-0.25198162  1.14326741]\n",
      " [ 0.22767883  0.08794365]\n",
      " [ 1.09106764  0.58629098]\n",
      " [-0.25198162 -0.29314549]\n",
      " [-1.01943834 -1.11395286]\n",
      " [-0.82757416  0.41040368]\n",
      " [-0.82757416 -0.23451639]\n",
      " [-0.06011744 -1.05532376]\n",
      " [ 0.5154751   1.87613113]\n",
      " [-1.88282715 -0.73286372]\n",
      " [-0.73164207  1.3777838 ]\n",
      " [ 0.99513555  2.11064752]\n",
      " [-1.4031667  -0.61560553]\n",
      " [ 1.09106764  0.55697643]\n",
      " [-0.25198162 -0.55697643]\n",
      " [-0.82757416  0.41040368]\n",
      " [-1.21130252 -1.05532376]\n",
      " [ 2.05038854  1.78818748]\n",
      " [ 0.32361092  0.0586291 ]\n",
      " [ 0.32361092 -0.70354917]\n",
      " [-0.06011744  0.23451639]\n",
      " [ 1.76259227 -0.26383094]\n",
      " [-0.82757416  0.32246004]\n",
      " [ 0.99513555 -1.05532376]\n",
      " [-1.30723461 -1.46572744]\n",
      " [-0.06011744  0.29314549]\n",
      " [-0.25198162  0.55697643]\n",
      " [-0.06011744  1.99338932]\n",
      " [ 1.85852436 -0.26383094]\n",
      " [-0.4438458  -0.52766188]\n",
      " [-0.34791371 -0.76217827]\n",
      " [-0.15604953 -0.26383094]\n",
      " [ 0.89920346 -1.43641289]\n",
      " [-1.30723461  0.43971823]\n",
      " [-0.53977789  1.93476022]\n",
      " [ 0.32361092 -0.49834733]\n",
      " [-1.11537043 -1.14326741]\n",
      " [-0.15604953 -0.17588729]\n",
      " [-0.92350625 -0.73286372]\n",
      " [-0.25198162 -0.73286372]\n",
      " [ 0.89920346  1.11395286]\n",
      " [-0.4438458   2.34516391]\n",
      " [-0.73164207  0.29314549]\n",
      " [-0.92350625 -0.93806556]\n",
      " [ 0.99513555  0.14657274]\n",
      " [-0.06011744  0.14657274]\n",
      " [ 1.37886391 -0.90875101]\n",
      " [-0.34791371 -1.28984015]\n",
      " [ 0.03581465 -0.55697643]\n",
      " [-0.25198162 -1.28984015]\n",
      " [-1.11537043 -1.08463831]\n",
      " [ 0.5154751   1.2605256 ]\n",
      " [ 0.32361092 -0.29314549]\n",
      " [ 2.05038854  0.20520184]\n",
      " [-0.25198162  0.08794365]\n",
      " [ 0.99513555  0.61560553]\n",
      " [ 0.03581465  1.2605256 ]\n",
      " [ 0.13174674 -0.23451639]\n",
      " [ 0.41954301  0.02931455]\n",
      " [-0.53977789 -1.49504199]\n",
      " [ 2.05038854 -1.17258195]\n",
      " [-1.59503088  0.08794365]\n",
      " [ 1.95445645  0.93806556]\n",
      " [-0.06011744 -0.46903278]\n",
      " [ 1.37886391  2.02270387]\n",
      " [-0.53977789 -1.49504199]\n",
      " [-0.25198162 -0.26383094]\n",
      " [-0.15604953  0.87943647]\n",
      " [ 1.95445645  0.76217827]\n",
      " [-1.01943834 -0.35177459]\n",
      " [-0.06011744  0.08794365]\n",
      " [ 0.32361092  0.32246004]\n",
      " [ 0.41954301 -0.1172582 ]\n",
      " [-1.01943834 -1.43641289]\n",
      " [-0.25198162 -0.87943647]\n",
      " [ 0.80327137 -1.3777838 ]\n",
      " [-1.01943834 -1.52435654]\n",
      " [-0.82757416  2.31584936]\n",
      " [-0.4438458  -1.11395286]\n",
      " [ 0.70733928  0.29314549]\n",
      " [-0.15604953 -0.49834733]\n",
      " [ 0.41954301  0.29314549]\n",
      " [ 1.95445645 -0.64492007]\n",
      " [ 0.70733928 -1.08463831]\n",
      " [ 2.14632063  0.41040368]\n",
      " [-0.25198162 -1.23121105]\n",
      " [ 0.89920346 -0.76217827]\n",
      " [-0.82757416  0.17588729]\n",
      " [-1.01943834  0.43971823]\n",
      " [-0.15604953  1.67092928]\n",
      " [ 0.80327137 -0.82080737]\n",
      " [ 0.13174674  0.17588729]\n",
      " [ 2.14632063  1.14326741]\n",
      " [ 0.70733928 -1.3777838 ]\n",
      " [-0.73164207 -1.52435654]\n",
      " [ 1.09106764  2.11064752]\n",
      " [ 0.89920346 -0.58629098]\n",
      " [ 0.32361092 -0.49834733]\n",
      " [ 0.89920346 -1.34846925]\n",
      " [-0.06011744 -0.20520184]\n",
      " [ 2.05038854 -0.79149282]\n",
      " [-0.25198162  0.1172582 ]\n",
      " [ 1.57072809  1.02600921]\n",
      " [ 0.80327137 -0.29314549]\n",
      " [ 1.37886391  0.61560553]\n",
      " [-0.82757416 -0.64492007]\n",
      " [-0.73164207  0.32246004]\n",
      " [ 0.80327137 -1.08463831]\n",
      " [ 0.03581465 -0.55697643]\n",
      " [-0.53977789  1.40709835]\n",
      " [ 1.95445645 -0.90875101]\n",
      " [-1.11537043  0.08794365]\n",
      " [-1.30723461 -0.32246004]\n",
      " [-0.34791371 -0.76217827]\n",
      " [-0.92350625  0.29314549]\n",
      " [-0.34791371  1.2605256 ]\n",
      " [-0.4438458   1.28984015]\n",
      " [ 0.99513555  2.02270387]\n",
      " [ 2.05038854  0.55697643]\n",
      " [ 0.41954301 -0.46903278]\n",
      " [ 1.28293182 -1.34846925]\n",
      " [-0.92350625  0.43971823]\n",
      " [-1.11537043  0.32246004]\n",
      " [-1.21130252  0.61560553]\n",
      " [-1.30723461 -0.41040368]\n",
      " [ 0.13174674 -0.79149282]\n",
      " [ 1.474796    0.38108914]\n",
      " [ 0.03581465 -0.52766188]\n",
      " [-1.88282715 -0.49834733]\n",
      " [ 1.18699973 -0.73286372]\n",
      " [-0.53977789  1.40709835]\n",
      " [-0.15604953 -1.05532376]\n",
      " [ 1.85852436 -1.2605256 ]\n",
      " [-0.92350625  0.52766188]\n",
      " [-1.78689506  0.20520184]\n",
      " [-0.25198162 -0.46903278]\n",
      " [ 2.05038854  2.16927662]\n",
      " [-0.25198162 -0.35177459]\n",
      " [ 0.22767883  0.17588729]\n",
      " [-0.63570998  0.0586291 ]\n",
      " [-1.11537043 -1.52435654]\n",
      " [ 0.41954301 -0.1172582 ]\n",
      " [-0.63570998  0.20520184]\n",
      " [-0.06011744  0.17588729]\n",
      " [-0.73164207 -0.20520184]\n",
      " [-0.15604953  0.17588729]\n",
      " [ 0.70733928 -1.2605256 ]\n",
      " [ 0.32361092  0.52766188]\n",
      " [ 0.22767883  1.11395286]\n",
      " [-0.25198162  0.08794365]\n",
      " [-0.06011744  0.26383094]\n",
      " [ 1.37886391  1.3191547 ]\n",
      " [ 1.85852436  1.55367109]\n",
      " [-0.25198162  0.82080737]\n",
      " [-0.4438458  -0.82080737]\n",
      " [ 0.32361092 -0.26383094]\n",
      " [ 1.09106764  0.49834733]\n",
      " [ 0.89920346  1.05532376]\n",
      " [ 0.99513555  0.79149282]\n",
      " [-0.25198162  2.28653481]\n",
      " [ 0.80327137  0.38108914]\n",
      " [-1.30723461 -1.34846925]\n",
      " [ 2.05038854  0.41040368]\n",
      " [-0.15604953 -0.43971823]\n",
      " [ 0.03581465  0.0586291 ]\n",
      " [-1.69096297 -1.34846925]\n",
      " [ 0.89920346 -1.28984015]\n",
      " [-0.25198162 -0.41040368]\n",
      " [-1.01943834  1.99338932]\n",
      " [ 0.22767883 -0.35177459]\n",
      " [-0.25198162 -0.64492007]\n",
      " [-0.63570998 -1.49504199]\n",
      " [-1.4031667  -0.17588729]\n",
      " [-1.11537043 -0.49834733]\n",
      " [-0.25198162  0.64492007]\n",
      " [-1.11537043  0.43971823]\n",
      " [ 0.5154751   1.75887293]\n",
      " [-0.25198162 -0.23451639]\n",
      " [ 1.474796    1.02600921]\n",
      " [ 1.57072809 -1.2605256 ]\n",
      " [-0.25198162  0.23451639]\n",
      " [ 1.18699973 -1.43641289]\n",
      " [ 2.14632063 -0.79149282]\n",
      " [-0.4438458  -0.26383094]\n",
      " [-1.78689506  0.46903278]\n",
      " [ 0.80327137  0.55697643]\n",
      " [-0.06011744  0.02931455]\n",
      " [ 0.99513555  1.81750203]\n",
      " [ 1.95445645 -1.34846925]\n",
      " [ 0.22767883  0.0586291 ]\n",
      " [ 0.13174674  0.0586291 ]\n",
      " [-0.92350625  0.58629098]\n",
      " [-1.49909879 -1.49504199]\n",
      " [-0.92350625 -1.08463831]\n",
      " [-0.92350625 -0.41040368]\n",
      " [-1.01943834  0.58629098]\n",
      " [-1.11537043  1.43641289]\n",
      " [-0.73164207 -1.58298564]\n",
      " [ 1.66666018  1.64161474]\n",
      " [ 0.41954301  0.32246004]\n",
      " [ 1.09106764  0.14657274]\n",
      " [-0.25198162 -1.3777838 ]\n",
      " [-1.01943834  0.79149282]\n",
      " [-1.78689506 -1.40709835]\n",
      " [-0.73164207  1.93476022]\n",
      " [ 0.22767883 -0.26383094]\n",
      " [ 1.09106764 -1.2018965 ]\n",
      " [-1.30723461 -0.41040368]\n",
      " [-0.25198162 -0.90875101]\n",
      " [-0.73164207  0.52766188]\n",
      " [ 1.85852436 -1.05532376]\n",
      " [-0.63570998  0.58629098]\n",
      " [ 0.89920346 -1.14326741]\n",
      " [ 0.13174674 -0.79149282]\n",
      " [-0.06011744  0.32246004]\n",
      " [-1.21130252  0.52766188]\n",
      " [-1.21130252 -1.3777838 ]\n",
      " [-1.78689506  0.02931455]\n",
      " [-1.01943834 -0.32246004]\n",
      " [-0.73164207 -0.58629098]\n",
      " [ 1.28293182  1.90544568]\n",
      " [ 0.22767883  0.17588729]\n",
      " [ 0.13174674  0.23451639]\n",
      " [ 0.03581465 -0.23451639]\n",
      " [ 0.99513555 -0.99669466]\n",
      " [ 0.13174674  1.90544568]\n",
      " [-1.78689506 -1.46572744]\n",
      " [-1.49909879 -0.41040368]\n",
      " [ 1.95445645  2.19859116]\n",
      " [-1.11537043  0.35177459]\n",
      " [-1.78689506 -1.2605256 ]\n",
      " [ 0.32361092  0.08794365]\n",
      " [ 0.13174674  0.0586291 ]\n",
      " [ 0.32361092 -0.52766188]\n",
      " [-0.82757416 -0.76217827]\n",
      " [ 0.89920346  1.28984015]\n",
      " [ 0.22767883 -0.1172582 ]\n",
      " [ 1.18699973 -0.96738011]\n",
      " [-1.4031667   0.38108914]\n",
      " [-1.01943834 -0.43971823]\n",
      " [ 1.28293182  2.25722026]\n",
      " [-1.11537043 -0.99669466]\n",
      " [-1.88282715 -0.02931455]\n",
      " [-0.25198162 -0.55697643]\n",
      " [-0.06011744  2.19859116]\n",
      " [-0.06011744  2.25722026]\n",
      " [ 0.70733928  1.81750203]\n",
      " [-1.69096297  0.14657274]\n",
      " [-0.15604953  2.19859116]\n",
      " [-0.53977789  0.49834733]\n",
      " [ 1.66666018  1.78818748]\n",
      " [ 0.70733928 -0.70354917]\n",
      " [ 0.41954301  0.1172582 ]\n",
      " [ 0.13174674 -0.29314549]\n",
      " [-0.25198162 -1.43641289]\n",
      " [-1.49909879 -1.23121105]\n",
      " [ 2.14632063 -1.02600921]\n",
      " [ 0.03581465 -0.1172582 ]\n",
      " [-1.11537043  0.32246004]\n",
      " [ 0.32361092  0.08794365]\n",
      " [-0.53977789  2.37447846]\n",
      " [ 0.32361092 -0.17588729]\n",
      " [-1.49909879  0.35177459]\n",
      " [-1.30723461 -1.23121105]\n",
      " [ 0.89920346 -1.02600921]\n",
      " [ 0.99513555  1.46572744]\n",
      " [-1.01943834  0.61560553]\n",
      " [ 0.61140719 -0.87943647]\n",
      " [-1.11537043  0.49834733]\n",
      " [-1.69096297 -0.96738011]\n",
      " [ 0.03581465 -0.23451639]\n",
      " [-0.06011744 -0.35177459]\n",
      " [-1.4031667  -0.08794365]\n",
      " [-0.92350625 -0.29314549]\n",
      " [ 0.89920346 -0.55697643]\n",
      " [ 0.32361092  0.29314549]]\n"
     ]
    }
   ],
   "source": [
    "# 导入标准化器\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "sc_X = StandardScaler()\n",
    "X_train = sc_X.fit_transform(X_train) # 在训练集上进行标准化操作\n",
    "\n",
    "print(X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "6ae4bddc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-2 {color: black;background-color: white;}#sk-container-id-2 pre{padding: 0;}#sk-container-id-2 div.sk-toggleable {background-color: white;}#sk-container-id-2 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-2 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-2 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-2 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-2 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-2 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-2 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-2 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-2 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-2 div.sk-item {position: relative;z-index: 1;}#sk-container-id-2 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-2 div.sk-item::before, #sk-container-id-2 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-2 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-2 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-2 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-2 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-2 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-2 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-2 div.sk-label-container {text-align: center;}#sk-container-id-2 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-2 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KNeighborsClassifier()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">KNeighborsClassifier</label><div class=\"sk-toggleable__content\"><pre>KNeighborsClassifier()</pre></div></div></div></div></div>"
      ],
      "text/plain": [
       "KNeighborsClassifier()"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入 KNeighborsClassifier 类，该类实现了 k-近邻分类器。\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "# metric=\"minkowski\", p=2 为欧氏距离\n",
    "# metric=\"minkowski\", p=1 为曼哈顿距离\n",
    "classifer=KNeighborsClassifier(n_neighbors=5, metric=\"minkowski\", p=2)\n",
    "# 将训练集数据传入模型，初始化一些参数，但不会计算\n",
    "classifer.fit(X_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "23fd4aec",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[56  4]\n",
      " [ 9 31]]\n"
     ]
    }
   ],
   "source": [
    " # 在测试集上进行标准化操作\n",
    "X_test = sc_X.fit_transform(X_test) \n",
    "# 使用测试集进行预测\n",
    "y_pred = classifer.predict(X_test)\n",
    "\n",
    "# 将测试集的y和预测的y传入，计算出混淆矩阵\n",
    "cm = confusion_matrix(y_test, y_pred)\n",
    "print(cm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "ab42b07a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay at 0x21db8ee57e0>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAfIAAAGwCAYAAABSAee3AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy88F64QAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAtgUlEQVR4nO3de3gU9dn/8c8EyCaBJByEDZEAQcP5IAcNwSpQBY2WB8r1qyLUB1tQES3mRxVq86ixlUR4WoxKRaQtpP5K1WpFay0ljwc8IBUQlAJF0QBBiAFBExKSkN35/YHs4xoOu5nd7M7O+3Vdc13ud3Zm7iAXd+77+50ZwzRNUwAAwJbiIh0AAABoPhI5AAA2RiIHAMDGSOQAANgYiRwAABsjkQMAYGMkcgAAbKx1pAOwwuv16sCBA0pOTpZhGJEOBwAQJNM0VV1drfT0dMXFha+2rKurU0NDg+XzxMfHKyEhIQQRhY6tE/mBAweUkZER6TAAABaVl5erW7duYTl3XV2dMnu0U0Wlx/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PPNvleY2OjNm3apEsuuUSStGvXLn355Zfq27evpJN/brt27QrqzxpA6JDIga9deeWVysnJ0aRJk7Rw4UL16dNHBw4c0CuvvKJJkyZpxIgRuvPOOzV9+nSNGDFC3/nOd/THP/5R27dvV69evU57zoSEBM2fP1/z5s1TfHy8Lr30Uh06dEjbt2/XjBkz1KVLFyUmJmrNmjXq1q2bEhISlJqaqoKCAs2ZM0cpKSnKzc1VfX29Nm3apKNHj2ru3LmaOnWq8vPzNWPGDP3Xf/2X9uzZo1/96ldB/bwXXHCBGhsb9dhjj2nChAl655139MQTTzT5Xps2bfSTn/xEjz76qNq0aaM77rhDI0eO9CX2++67T9/73veUkZGhH/zgB4qLi9OHH36obdu26cEHHwz+fwSAoLBqHfiaYRh65ZVXdPnll+vHP/6xevfurSlTpmjPnj2+VebXX3+97rvvPs2fP1/Dhw/X3r17ddttt531vPfee69++tOf6r777lO/fv10/fXXq7KyUtLJ+edHH31Uy5YtU3p6uiZOnChJmjlzpn77299q5cqVGjRokEaPHq2VK1f6bldr166d/vrXv2rHjh0aOnSo8vPztXDhwqB+3osuukiLFy/WwoULNXDgQP3xj39UUVFRk+8lJSVp/vz5mjp1qnJycpSYmKinn37at/+qq67Syy+/rNLSUl188cUaOXKkFi9erB49egQVD4DmMcxQTLYBAICIoCIHAMDGSOQAANgYiRwAABsjkQMAYGMkcgAAbIxEDgCAjZHIAQCwMRI5AAA2RiIHAMDGSOQAANgYiRwAABv7//aQt+PK5qSgAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 一图胜千言，使用图像展示混淆矩阵\n",
    "from sklearn.metrics import ConfusionMatrixDisplay\n",
    "\n",
    "disp = ConfusionMatrixDisplay(confusion_matrix=cm, \n",
    "                              display_labels=classifer.classes_)\n",
    "disp.plot()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84f25d32",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
